const merge = require('webpack-merge');
const base = require('./webpack.base.config');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const setFilePath = require('./webpack.setFilePath')


module.exports = merge(base,{
  mode:'development',
  devtool:'inline-source-map',
  devServer:{
    hot:true,
    port:8081,
    proxy:{
      '^api':'localhost:8080'
    },
    openPage:'/'+setFilePath+'.html'
  },
  module:{
    rules:[
      {
        test:/\.styl$/,
        exclude:/node_modules/,
        use:['style-loader','css-loader',
        {
          loader:'postcss-loader',
          options:{
            ident:'postcss',
            plugins:(loader)=>[
              require('autoprefixer')({
                browsers:[
                  '> 1%',
                  'last 5 versions',
                  'not ie <= 8',
                  'ios >= 6',
                  'android >= 4.0'
                ]
              })
            ]
          }
        },'stylus-loader']
      },
      // {
      //   test:/\.(png|jpg|gif|svg)$/i,
      //   use:[
      //     {
      //       loader:'url-loader',
      //       options:{
      //         name:'assets/[name].[ext]',
      //         limit:300000,
      //         publicPath:'http://shanzhouweb.com'
      //       }
      //     }
      //   ]
      // },
      {
        test:/\.html$/,
        exclude:/node_modules/,
        include:/pages/,
        use:['html-loader']
      },
      {
        test:/\.(png|jpg|gif|svg)$/i,
        use:[
          {
            loader:'file-loader',
            options:{
              name:'common/images/[name]-[hash:5].[ext]'
            }
          }
        ]
      },
      {
        test: require.resolve(base.context+'/src/common/js/jquery-3.3.1.min.js'),
        use: [{
          loader: 'expose-loader',
          options: '$'
        }]
      }
    ]
  },
  plugins:[
    new webpack.NamedModulesPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new CopyWebpackPlugin([ //支持输入一个数组
      {
        from: base.context+'/src/assets', //将src/assets下的文件
        to: base.context+'/dist/assets' // 复制到publiv
      },
      {
        from: base.context+'/src/common', //将src/assets下的文件
        to: base.context+'/dist/common' // 复制到publiv
      }
    ]),
  ]
})